package com.zezheng.extract.project.system.controller;

import java.util.List;

import com.zezheng.extract.project.system.domain.SysUserCollect;
import com.zezheng.extract.project.system.service.ISysUserCollectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zezheng.extract.framework.aspectj.lang.annotation.Log;
import com.zezheng.extract.framework.aspectj.lang.enums.BusinessType;
import com.zezheng.extract.framework.web.controller.BaseController;
import com.zezheng.extract.framework.web.domain.AjaxResult;
import com.zezheng.extract.common.utils.poi.ExcelUtil;
import com.zezheng.extract.framework.web.page.TableDataInfo;

/**
 * 用户收藏Controller
 *
 * @author cuijie
 * @date 2022-02-07
 */
@RestController
@RequestMapping("/system/user/collect")
public class SysUserCollectController extends BaseController
{
    @Autowired
    private ISysUserCollectService sysUserCollectService;

    /**
     * 查询用户收藏列表
     */
    @PreAuthorize("@ss.hasPermi('system:collect:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserCollect sysUserCollect)
    {
        startPage();
        sysUserCollect.setUserId(getUserId());
        List<SysUserCollect> list = sysUserCollectService.selectSysUserCollectList(sysUserCollect);
        return getDataTable(list);
    }

    /**
     * 导出用户收藏列表
     */
    @PreAuthorize("@ss.hasPermi('system:collect:export')")
    @Log(title = "用户收藏", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysUserCollect sysUserCollect)
    {
        List<SysUserCollect> list = sysUserCollectService.selectSysUserCollectList(sysUserCollect);
        ExcelUtil<SysUserCollect> util = new ExcelUtil<SysUserCollect>(SysUserCollect.class);
        return util.exportExcel(list, "用户收藏数据");
    }

    /**
     * 获取用户收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:collect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysUserCollectService.selectSysUserCollectById(id));
    }

    /**
     * 新增用户收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collect:add')")
    @Log(title = "用户收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserCollect sysUserCollect)
    {
        sysUserCollect.setUserId(getUserId());
        return toAjax(sysUserCollectService.insertSysUserCollect(sysUserCollect));
    }

    /**
     * 修改用户收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collect:edit')")
    @Log(title = "用户收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserCollect sysUserCollect)
    {
        return toAjax(sysUserCollectService.updateSysUserCollect(sysUserCollect));
    }

    /**
     * 删除用户收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collect:remove')")
    @Log(title = "用户收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysUserCollectService.deleteSysUserCollectByIds(ids));
    }
}
